//
//  Team9ExpertViewController.m
//  Team9Project
//
//  Created by 朱嘉祺 on 15/10/12.
//  Copyright © 2015年 apple. All rights reserved.
//

#import "Team9ExpertViewController.h"



#import "Team9DesingerViewController.h"
#import "Team9WorkViewController.h"
#import "Team9XioalLeiViewController.h"


@interface Team9ExpertViewController ()

//@property(nonatomic, strong)Team9DesingerViewController *desVC;
//@property(nonatomic, strong)Team9WorkViewController *workVC;
@property(nonatomic, strong)UIView *designerView;
@property(nonatomic, strong)UIView *workView;
@property(nonatomic, strong)UIButton *cityButton;
@property(nonatomic, strong) UISegmentedControl *seg;
@property(nonatomic, strong) NSString *cityId;

@end

@implementation Team9ExpertViewController
- (void)dealloc{
    [[NSNotificationCenter defaultCenter]removeObserver:self];
}
- (void)changecolor{
    if ([Team9EveningType shareEvening].eveningFailling) {
        self.seg.tintColor = [UIColor greenColor];
        [self.cityButton setTitleColor:[UIColor greenColor] forState:UIControlStateNormal];
    } else {
        self.seg.tintColor = [UIColor orangeColor];
        [self.cityButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
    }
}
#pragma mark 父视图控制器 通知中心方法
- (void)cityId:(NSNotification *)notification{
//    NSLog(@"%@", notification.userInfo);
    if (notification.userInfo != nil) {
        self.cityId = notification.userInfo[@"uId"];
        [self.cityButton setTitle:notification.userInfo[@"modelname"] forState:UIControlStateNormal];
    } else {
        self.cityId = nil;
        [self.cityButton setTitle:@"全部" forState:UIControlStateNormal];
    }
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(cityId:) name:@"sendData" object:nil];
    // Do any additional setup after loading the view.
    self.seg = [[UISegmentedControl alloc] initWithItems:@[@"设计师", @"工长"]];
    self.navigationItem.titleView = _seg;
    [_seg addTarget:self action:@selector(selectVC:) forControlEvents:UIControlEventValueChanged];
    [_seg setSelectedSegmentIndex:0];
    [self selectVC:_seg];

    
    self.cityButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.cityButton.frame = CGRectMake(0, 0, 60, 44);
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:_cityButton];
    [self.cityButton addTarget:self action:@selector(city:) forControlEvents:UIControlEventTouchUpInside];
    _cityButton.titleLabel.font = [UIFont fontWithName:@"CourierNewPSMT" size:14];
    [self.cityButton setTitle:@"城市" forState:UIControlStateNormal];
    [self.cityButton setTitleColor:[UIColor orangeColor] forState:UIControlStateNormal];
//    self.navigationController.navigationBar.translucent = NO;
//    self.tabBarController.tabBar.translucent = NO;
}
- (void)city:(id)sender{
    self.hidesBottomBarWhenPushed = YES;
    Team9XioalLeiViewController *vc = [Team9XioalLeiViewController new];
    vc.url = @"http://api.meilijia.com/app/advanced_pro_zone_list";
    [self.navigationController pushViewController:vc animated:YES];
    self.hidesBottomBarWhenPushed = NO;
//    NSLog(@"test");
}
#pragma mark 选择按钮
- (void)selectVC:(UISegmentedControl *)seg{
    switch (seg.selectedSegmentIndex) {
        case 0:
            [self.designerView setHidden:NO];
            break;
        case 1:
            [self.workView setHidden:NO];
            [self.designerView setHidden:YES];
            break;
        default:
            break;
    }
}
// lazy loading
- (UIView *)designerView
{
    if (!_designerView) {
        Team9DesingerViewController *desVC = [Team9DesingerViewController new];
        [self addChildViewController:desVC];
//        desVC.viewCotroller = self;
        _designerView = desVC.view;
        _designerView.frame = [UIScreen mainScreen].bounds;
        [self.view addSubview:_designerView];
    }
    [self.view bringSubviewToFront:_designerView];
    return _designerView;
}
- (UIView *)workView
{
    if (!_workView) {
        Team9WorkViewController *workVC = [Team9WorkViewController new];
        [self addChildViewController:workVC];
        self.workView = workVC.view;
        workVC.cityId = self.cityId;
        self.workView.frame = [UIScreen mainScreen].bounds;
        [self.view addSubview:_workView];
    }
    [self.view bringSubviewToFront:_workView];
    return _workView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
